﻿using System;   
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TT.Module.sysLogin;
using System.Data;
using TT.ORM;

namespace Exp.BillDLL.dao
{
    public class daoExpBill
    {
        etyBaeSystemParamter basSysParam;

        public daoExpBill(etyBaeSystemParamter ibasSysParam)
        {
            basSysParam = ibasSysParam;
        }

        public DataTable GetCodeRef(etyCodeRef inEty)
        {
            bool isHadWhere=false;
            string sql = "select ITEM,ITEM_DESC,CODE,CODE_DESC,VALUE,AVAIL_IND,REMARK,LST_UPD_DATE,RESULT_IND,PRINT_GRP"
                +" from code_ref ";
            #region 设置条件
            if (inEty.ITEM.Trim() != "")
            {
                if (isHadWhere == false)
                {
                    sql += " where ";
                    isHadWhere = true;
                }
                sql += " item=:item ";
                isHadWhere = true;
            }
            if (inEty.CODE.Trim() != "")
            {
                if (isHadWhere == false)
                {
                    sql += " where ";
                    isHadWhere = true;
                }
                sql += " code=:code ";
            }
            #endregion 

            //sql += " union select '***','***','***','***','***','','',sysdate,'','' from dual "
            sql += " order by code,value ";

            //IList<etyCodeRef> ilEty = new List<etyCodeRef>();
            //ilEty.Add(inEty);
            return basSysParam.SqlHelp.ExecuteReader(sql, inEty);
        }

        /// <summary>
        /// 获取基础数据结构一致的表
        /// </summary>
        /// <returns></returns>
        public DataTable GetBaseTableCodeName(string sTableName, int iColumnOrderIdx, string sFields, string sWhere)
        {
            string sql = string.Empty;
            if (sFields.Trim() == "")
                sql = "select X_CODE,X_NAME,'' X_ID from ";
            else
                sql = "select " + sFields + " from ";
            sql += sTableName;
            if (sWhere.Trim() != "")
            {
                sql += " " + sWhere;
            }
            //sql += " UNION select null,null,null from dual ORDER BY ";
            sql += " ORDER BY ";
            sql += (iColumnOrderIdx + 1).ToString();
            DataTable dt = basSysParam.SqlHelp.ExecuteReader(sql);
            return dt;
        }

        public DataTable GetClient()
        {
            string sql = string.Empty;
            sql = "select CLIENT_NO,CLIENT_NAME,CLIENT_ID from bas_client "
                + " order by CLIENT_ID ";
            DataTable dt;
            dt = basSysParam.SqlHelp.ExecuteReader(sql, new string[] { });
            return dt;
        }
    }
}
